package org.imraniqbal.engine;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

/**
 * @author  imran
 */
public class GameController extends KeyAdapter {
	/**
	 * @author   imran
	 */
	public enum Controls{/**
	 * @uml.property  name="uP"
	 * @uml.associationEnd  
	 */
	UP, /**
	 * @uml.property  name="dOWN"
	 * @uml.associationEnd  
	 */
	DOWN, /**
	 * @uml.property  name="lEFT"
	 * @uml.associationEnd  
	 */
	LEFT, /**
	 * @uml.property  name="rIGHT"
	 * @uml.associationEnd  
	 */
	RIGHT, /**
	 * @uml.property  name="aCTION"
	 * @uml.associationEnd  
	 */
	ACTION};
	
	/**
	 * @uml.property  name="g"
	 * @uml.associationEnd  
	 */
	private Game g;
	/**
	 * @uml.property  name="gp"
	 * @uml.associationEnd  
	 */
	private GamePanel gp;
	/**
	 * Create a controller for the game
	 * @param g the game you want a controller for
	 */
	public GameController(Game g, GamePanel gp){
		this.g = g;
		this.gp = gp;
	}
	/**
	 * Sends the game a control bases on keyboard input
	 */
	@Override
	public void keyPressed(KeyEvent e){
		switch(e.getKeyCode()){
		case KeyEvent.VK_UP:
			g.getControl(Controls.UP);
			break;
		case KeyEvent.VK_DOWN:
			g.getControl(Controls.DOWN);
			break;
		case KeyEvent.VK_LEFT:
			g.getControl(Controls.LEFT);
			break;
		case KeyEvent.VK_RIGHT:
			g.getControl(Controls.RIGHT);
			break;
		case KeyEvent.VK_SPACE:
			g.getControl(Controls.ACTION);
			break;
		}
		gp.repaint();
	}
}
